﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Windows;

namespace Shakes_and_Fidget_Charplaner
{
    static class Program
    {
        public static StreamWriter log = new StreamWriter(Environment.CurrentDirectory + "\\log.txt", true);
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            log.AutoFlush = true;
            if (!File.Exists(Environment.CurrentDirectory + "\\log.txt"))
                File.Create(Environment.CurrentDirectory + "\\log.txt");

            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new sfc());
            }
            catch (Exception e)
            {
                LogWrite(e);
            }
            finally
            { log.Close(); }
            
        }
        public static void LogWrite(Exception e)
        {
            log.Write("[" + DateTime.Now + "]" + e.Message);
            log.Write("\r\n[Stack Trace]\r\n" + e.StackTrace + "\r\n [STACK TRACE END]\r\n");
            log.Write("[Source] " + e.Source + "[SOURCE END]\r\n");
            MessageBox.Show("Es ist ein Fehler in der Anwendung aufgetreten.\r\nBitte sende die Datei \r\n\n\"" + Environment.CurrentDirectory + "\\log.txt\"\r\n\nan einen Entwickler.\r\n" + e.Message, e.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}
